﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.Diagnostics;
using System.Windows.Forms;

namespace JetLoginTool.Engine
{
	public static class StartUpHelper
	{
		public static void toggleStartWithWindows(bool startWithWindows)
		{
			RegistryKey runRegistry = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
			if (runRegistry != null)
			{
				string runRegistryValue = (string)runRegistry.GetValue("JetLoginTool", "");

				ProcessStartInfo startInfo = new ProcessStartInfo(Application.StartupPath + "\\ChangeStartUp.exe",
																  "JetLoginTool \"" + Application.ExecutablePath + "\" ");

				try
				{
					if ((startWithWindows) && (string.IsNullOrEmpty(runRegistryValue)))
					{
						startInfo.Arguments += "enable";
						Process.Start(startInfo);
					}
					else if ((!startWithWindows) && (!string.IsNullOrEmpty(runRegistryValue)))
					{
						startInfo.Arguments += "disable";
						Process.Start(startInfo);
					}
				}
				catch
				{
				}
			}
		}
	}
}
